﻿using DataAccess;
using DevExpress.XtraEditors;
using System;
using System.Windows.Forms;

namespace QuanLyKhachSan
{
    public partial class FormQuyenCapNhat : XtraForm
    {
        public Quyen Quyen = new Quyen();
        private ActionResult _atcion = new ActionResult();
        public bool Success { get; set; }

        public FormQuyenCapNhat()
        {
            InitializeComponent();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void LayGiaTri()
        {
            try
            {
                Quyen.MaQuyen = txtMaQuyen.Text;
                Quyen.TenQuyen = txtTenQuyen.Text;
                Quyen.TrangThai = txtTrangthai.Text;
            }
            catch 
            {
                XtraMessageBox.Show("Lỗi khi nhập giá trị", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            LayGiaTri();
            _atcion = new QuyenManager().Them(Quyen);
            if (!_atcion.Sucess())
                XtraMessageBox.Show(_atcion.GetErrorMessage(),"Lỗi",MessageBoxButtons.OK,MessageBoxIcon.Error);
            else
            {
                Success = true;
                this.Close();
            }
        }
    }
}
